def f (a):
    for i in range(2,a):
        if a%i == 0:
            return(0)
    return(a)


a = int(input())
if a<1000 or a>9999:
    print ('0')
else:
    b = a%10
    d = (a//10)%10
    c = (a//100)%10
    e = a//1000

    mas = [0]*10
    mas[0] = b
    mas[1] = c
    mas[2] = e
    mas[3] = d
    mas[4] = e*10+c
    mas[5] = c*10+d
    mas[6] = d*10+b
    mas[7] = e*100+c*10+d
    mas[8] = c*100+d*10+b
    mas[9] = a

    maxi = 0
    for i in mas:
        t=f(i)
        if t!=0 and t > maxi:
            maxi = t
    print(maxi)

    
    